package cn.bnjy.task;

import cn.bnjy.common.WeiXinAccessToken;
import cn.bnjy.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * 描述：定时获取access_token
 *
 * @date: 2018/11/3 15:12
 * @author: chavin
 */
@Component
@Slf4j
public class AccessTokenTask {

    @Scheduled(cron = "0 0 0/2 * * *")
    public void createAccessToken( ){
        log.info("自动执行开始：获取access_token，当前时间：", DateUtils.getDateStr(new Date(), null));
        LocalDateTime startTime = LocalDateTime.now();
        WeiXinAccessToken.getTokenFromWeiXin();
        LocalDateTime endTime = LocalDateTime.now();
        long time = ChronoUnit.MILLIS.between(startTime, endTime);
        log.info("自动执行结束：获取access_token，当前时间：" + DateUtils.getDateStr(new Date(), null) + "，耗时：{}ms", time);
    }

}
